package com.example.mylibrarybase.yumengmeng25.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import com.example.mylibrarybase.utils.LogUtils;
import com.example.mylibrarybase.yumengmeng25.bean.result_;


/**
 * Created by 35876 于萌萌
 * 创建日期: 11:25 . 2016年11月08日
 * 描述:
 * <p>
 * <p>
 * 备注:13664608180
 */

class userRegist extends Thread implements Runnable {
    NetAesCallBack netAesCallBack;
    public userRegist(NetAesCallBack netAesCallBack) {
        this.netAesCallBack = netAesCallBack;
    }

    @Override
    public void run() {
        super.run();
        // TODO Auto-generated method stub
        try {
            // SharedPreferences settings = getSharedPreferences("settings", 0);
            JSONObject msgObject = new JSONObject();
            msgObject.put("action", "getXinXi");
            // msgObject.put("passenger_telephone", settings.getString("passenger_telephone", "13664608180"));
            msgObject.put("passenger_telephone", "13664608180");
            // 上传的参数
            String para = "para=" + AES.encrypt(Constants.key, Constants.iv, msgObject.toString());
            System.out.println(msgObject.toString());
            // 返回的加密串
            String str = Utils.postUrlData(Constants.new_url, para);
            LogUtils.i("返回回来的加密数据为"+str);
            //解谜之后
            String decrypt = AES.decrypt(Constants.key, Constants.iv, str);
            LogUtils.i("json"+decrypt);
            JSONObject jsonObject = JSON.parseObject(decrypt);
            result_ data = jsonObject.getObject("data", result_.class);
            LogUtils.i("data"+data);

           // netAesCallBack.getAesString(decrypt);

//            // 构建handler
//            Message msg = userRegistHandler.obtainMessage();
//            Bundle bundle = new Bundle();
//            bundle.putString("userRegist", str);
//            msg.setData(bundle);
//            userRegistHandler.sendMessage(msg);
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

//
//    /**
//     * 界面handler
//     */
//    Handler userRegistHandler = new Handler() {
//        @Override
//        public void handleMessage(Message msg) {
//            try {
//                String str = AES.decrypt(Constants.key, Constants.iv, msg.getData().getString("userRegist"));
//                JSONObject obj = new JSONObject(str);
//                Log.i("str", str);
//                // 有数据
//                if (obj.getString("result").equals("1")) {
//                    JSONObject obj_ = new JSONObject(obj.getString("data"));
//
//                    if (!obj_.getString("passenger_photo").equals("")) {
//                        //bmpManager.loadBitmap(Constants.fangwen_image_url + obj_.getString("passenger_photo"), passenger_photo);
//
//                    }
//
////                    EditText passenger_nickname = (EditText) findViewById(R.id.passenger_nickname);
////                    passenger_nickname.setText(obj_.getString("passenger_nickname"));
////
////                    Button passenger_sex = (Button) findViewById(R.id.passenger_sex);
////                    passenger_sex.setText(obj_.getString("passenger_sex"));
////
////                    Button passenger_industry = (Button) findViewById(R.id.passenger_industry);
////                    passenger_industry.setText(obj_.getString("passenger_industry"));
////
////                    EditText passenger_job = (EditText) findViewById(R.id.passenger_job);
////                    passenger_job.setText(obj_.getString("passenger_job"));
//
//                } else {
//                    // Toast.makeText(PersonCenterXinXiActivity.this, obj.getString("message"), Toast.LENGTH_LONG).show();
//                }
//            } catch (Exception e) {
//                // TODO Auto-generated catch block
//                e.printStackTrace();
//            }
//        }
//    };
}

